<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取元素偏移量</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 500px;
            height: 500px;
            margin: 30px;
            background-color: skyblue;
            overflow: hidden;
            /* overflow:hidden解决外边距塌陷。 */
            /* position: relative; */
        }
        p{
            width: 300px;
            height: 300px;
            margin: 30px;
            background-color: orange;
            overflow: hidden;
            /* position: absolute; */
            /* position: relative; */
        }
        span{
            display: block;
            width: 100px;
            height: 100px;
            margin: 30px;
            background-color: pink;

            /* position: absolute; */
            /* left: 30px;
            top: 30px; */
            /* right: 30px;
            bottom: 30px; */
        }
    </style>
</head>
<body>
    <div>
        <p>
            <span></span>
        </p>
    </div>
    <script src="./jquery.js"></script>
    <script>
        /*
        操作元素偏移量
        */

        //1.offset()
        //获取元素相对于页面左上角的坐标位置
        //注意：返回值是一个对象数据类型，｛top：yyy,left:xxx｝
        console.log('div :',$('div').offset())//div : {top: 30, left: 30}
        console.log('p:',$('p').offset())//p: {top: 60, left: 60}
        console.log('span:',$('span').offset())//span: {top: 90, left: 90}

        //2.position()
        //获取的就是元素的定位位置
        //注意：如果你设置的说right和bottom，会自动帮你换算成left和top的值
        // console.log($('span').position())//{top: 30, left: 30}  换算后显示{top: 170, left: 170}

    </script>
</body>
</html>